home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / mail-tools / thor / thor_2.22 / thor.lha / rexx / SortMail.thor < prev    next >
Text File  |  1995-05-02  |  24KB  |  764 lines

  1. /*
  2. ** $VER: SortMail.thor 2.2b (29.11.95)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** Some code borrowed from  AddSOUP.thor      by Magne Østlyngen
  6. **                     and  AddAmiNetList.br  by Petter Nilsen
  7. **
  8. **
  9. ** Todo:  Finish SortMail 3.0 :^)
  10. **
  11. */
  12.  
  13. options results
  14.  
  15. signal on break_c
  16. signal on halt
  17. signal on syntax
  18.  
  19. /* Initialize some variables */
  20.  
  21. system = ""; mailconf = ""
  22. aminet = ""; delaminet = 0; amirep = ""; amilink = ""; checkcc= 0; stats = 0; delusers = 0
  23. mlcount = 0; dgcount = 0
  24. mlfound = 0; dgparsed = 0 ; dgsubmsgs = 0; rparsed = 0; rfiles = 0; aruu = 0; aluu = 0;
  25. progwin = 0; delnew = 0
  26.  
  27. MDB_DELETED             =  5  /* Message is deleted. */
  28. MDB_SUPERMARKED         = 13  /* Message will not be unmarked as long as this flag is set. */
  29.  
  30.  
  31. /* Find Thor and BBSREAD ARexx ports' */
  32.  
  33. p=address()||' '||show('P',,);if pos('THOR.',p)>0 then thorport=word(substr(p,pos('THOR.',p)),1);else do;say 'No THOR port found!';exit(0);end
  34. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  35.  
  36. address(thorport)
  37.  
  38. /* See if another copy of SortMail is already running */
  39.  
  40. if exists("T:SortMail.tmp") then do
  41.     REQUESTNOTIFY '"Another copy of SortMail\nis probably running."' '"Continue|Abort"'
  42.     if result = 0 then exit(0)
  43.     end
  44.  
  45. call open(tmp, "T:SortMail.tmp", 'W'); call close(tmp)
  46.  
  47. /* Get the path of the configuration file */
  48.  
  49. call open(pn, 'ENV:Thor/THORPATH', 'R')
  50. thorpath = readln(pn)
  51. call close(pn)
  52.  
  53. if ~exists(thorpath'rexx') then cfgfile = 'ENV:Thor/SortMail.cfg'
  54. else do
  55.  if exists(thorpath'rexx/SortMail.cfg') then cfgfile = thorpath'rexx/SortMail.cfg'
  56.  else cfgfile = 'ENV:Thor/SortMail.cfg'
  57.  end
  58.  
  59. if ~exists(cfgfile) then do
  60.     REQUESTNOTIFY '"Couldn''t find config file ('cfgfile').\nPlease run CfgSortMail.thor and try again."' '"Abort"'
  61.     signal cleanup
  62.     end
  63.  
  64. /* Check if user has entered a system or is in the startup window */
  65.  
  66. CURRENTSYSTEM STEM bbs
  67. if rc = 1 then do
  68.     REQUESTNOTIFY '"Enter your configured system\nbefore running this script."' '"Abort"'
  69.     signal cleanup
  70.     end
  71. else if rc ~= 0 then do
  72.     REQUESTNOTIFY '"CURRENTBBS:\n'THOR.LASTERROR'"' '"Abort"'
  73.     signal cleanup
  74.     end
  75.  
  76. /* Read configuration */
  77.  
  78. call readcfg
  79.  
  80. /* Get conference list */
  81.  
  82. address(bbsread)
  83. GETCONFLIST BBSNAME '"'system'"' STEM conflist
  84. if rc ~= 0 then do
  85.     address(thorport)
  86.     REQUESTNOTIFY '"GETCONFLIST:\n'BBSREAD.LASTERROR'"' '"Abort"'
  87.     signal cleanup
  88.     end
  89.  
  90. /* Exit if there are no messages to process */
  91.  
  92. if msgs.count = 0 then signal cleanup
  93.  
  94. /* Open progressbar */
  95.  
  96. address(thorport)
  97. OPENPROGRESS TITLE '"Sorting messages..."' TOTAL msgs.count AT "_Abort" PROGRESSCHARWIDTH 38
  98. if rc = 0 then progwin = result
  99. else do
  100.     REQUESTNOTIFY '"OPENPROGRESS:\n'THOR.LASTERROR'"' '"Abort"'
  101.     signal cleanup
  102.     end
  103.  
  104. /* Turn on copyback buffer */
  105.  
  106. address(bbsread)
  107. BUFMODE COPYBACK
  108.  
  109. /***************************** Start of main loop ****************************/
  110.  
  111. do curr = 1 to msgs.count
  112.     msgfini = 0; textread = 0
  113.  
  114.     /* Update progressbar */
  115.     address(thorport)
  116.     UPDATEPROGRESS REQ progwin CURRENT curr PT '"Message 'curr' of 'msgs.count' (OrgMsg: 'msgs.curr')"'
  117.     if rc ~= 0 then signal cleanup
  118.  
  119.     /* Read message data */
  120.     address(bbsread)
  121.     drop data. head.
  122.     READBRMESSAGE '"'system'"' '"'mailconf'"' msgs.curr DATASTEM data HEADSTEM head
  123.     if rc ~= 0 then do
  124.         address(thorport)
  125.         REQUESTNOTIFY '"Couldn''t read msg #'msgs.curr':\n'BBSREAD.LASTERROR'"' '"Ok"'
  126.         signal cleanup
  127.         end
  128.  
  129.     /* If messsage is marked as deleted or superunread then skip it */
  130.  
  131.     if bittst(data.FLAGS, MDB_SUPERMARKED) then msgfini = 1
  132.     if bittst(data.FLAGS, MDB_DELETED) then msgfini = 1
  133.     if msgfini = 1 then iterate curr
  134.  
  135.     /* Check if message is part of a mailing list */
  136.  
  137.     if mlcount > 0 then do
  138.         do m = 1 to mlcount until msgfini = 1
  139.             searchaddr = upper(compress(head.TOADDR, ',<>()"'))
  140.             do n = 1 to mlist.m.addrcount until msgfini = 1
  141.                 if find(searchaddr, upper(mlist.m.toaddr.n)) > 0 then do
  142.                     call movemsg(msgs.curr, mlist.m.name, mlist.m.replyaddr)
  143.                     mlfound = mlfound + 1
  144.                     mlist.m.found = mlist.m.found + 1
  145.                     msgfini = 1
  146.                     end
  147.                 end
  148.             if msgfini = 0 then do n = 1 to mlist.m.namecount until msgfini = 1
  149.                 if upper(head.TONAME) = upper(mlist.m.toname.n) then do
  150.                     call movemsg(msgs.curr, mlist.m.name, mlist.m.replyaddr)
  151.                     mlfound = mlfound + 1
  152.                     mlist.m.found = mlist.m.found + 1
  153.                     msgfini = 1
  154.                     end
  155.                 end
  156.             end
  157.         end
  158.  
  159.     if msgfini = 1 then iterate curr
  160.  
  161.     /* Check if message is a digest */
  162.  
  163.     if dgcount > 0 then do
  164.         do m = 1 to dgcount until msgfini = 1
  165.             do n = 1 to digest.m.addrcount until msgfini = 1
  166.                 if find(upper(head.TOADDR), upper(digest.m.toaddr.n)) > 0 then do
  167.                     call parsedigest(msgs.curr, digest.m.name, digest.m.replyaddr, digest.m.endsubmsg, digest.m.enddigest, digest.m.deldigest, m)
  168.                     dgparsed = dgparsed + 1
  169.                     msgfini = 1
  170.                     end
  171.                 end
  172.             if msgfini = 0 then do n = 1 to digest.m.namecount until msgfini = 1
  173.                 if upper(head.TONAME) = upper(digest.m.toname.n) then do
  174.                     call parsedigest(msgs.curr, digest.m.name, digest.m.replyaddr, digest.m.endsubmsg, digest.m.enddigest, digest.m.deldigest, m)
  175.                     dgparsed = dgparsed + 1
  176.                     msgfini = 1
  177.                     end
  178.                 end
  179.             end
  180.         end
  181.  
  182.     if msgfini = 1 then iterate curr
  183.  
  184.     select 
  185.         /* Check if message is a aminet recent message */
  186.         when upper(head.TOADDR) = upper(aminet) then call parseaminet(msgs.curr)
  187.  
  188.         /* Check if message contains amiga report */
  189.         when upper(head.FROMADDR) = upper(amirep) then do
  190.             if exists(thorpath'rexx/UUDecode.thor') then do
  191.                 address(thorport)
  192.                 SAVEMESSAGE BBSNAME '"'system'"' CONFNAME '"'mailconf'"' MSGNUMBER msgs.curr NOHEADER NOANSI FILENAME '"T:AmiRep.uu"'
  193.                 address(command)
  194.                 'rx 'thorpath'rexx/UUDecode.thor T:AmiRep.uu'
  195.                 aruu = aruu + 1
  196.                 end
  197.             else do
  198.                 address(thorport)
  199.                 REQUESTNOTIFY '"Couldn''t uudecode Amiga Report:\n'thorpath'rexx/UUDecode.thor not found."' '"I see."'
  200.                 end
  201.             end
  202.  
  203.         /* Check if message contains amiga link */
  204.         when upper(head.FROMADDR) = upper(amilink) then do
  205.             if exists(thorpath'rexx/UUDecode.thor') then do
  206.                 address(thorport)
  207.                 SAVEMESSAGE BBSNAME '"'system'"' CONFNAME '"'mailconf'"' MSGNUMBER msgs.curr NOHEADER NOANSI FILENAME '"T:AmiLink.uu"'
  208.                 address(command)
  209.                 'rx 'thorpath'rexx/UUDecode.thor T:AmiLink.uu'
  210.                 aluu = aluu + 1
  211.                 end
  212.             else do
  213.                 address(thorport)
  214.                 REQUESTNOTIFY '"Couldn''t uudecode Amiga Link:\n'thorpath'rexx/UUDecode.thor not found."' '"I see."'
  215.                 end
  216.             end
  217.  
  218.         otherwise if msgfini = 0 then do
  219.             if checkcc = 1 then do
  220.                 /* <sigh> Apparently we'll have to check the COMMENT. too... */
  221.  
  222.                 drop text.
  223.                 address(bbsread)
  224.                 READBRMESSAGE '"'system'"' '"'mailconf'"' msgs.curr TEXTSTEM text
  225.                 textread = 1
  226.  
  227.                 if text.COMMENT.COUNT ~= 'TEXT.COMMENT.COUNT' then if text.COMMENT.COUNT > 0 then do n = 1 to text.COMMENT.COUNT until msgfini = 1
  228.                     if upper(left(text.COMMENT.n, 4)) = 'FROM' then do m = 1 to mlcount until msgfini = 1
  229.                             if index(upper(text.COMMENT.n), upper(mlist.m.fromf)) > 0 then do
  230.                                 call movemsg(msgs.curr, mlist.m.name, mlist.m.replyaddr)
  231.                                 mlfound = mlfound + 1
  232.                                 mlist.m.found = mlist.m.found + 1
  233.                                 msgfini = 1
  234.                                 end
  235.                             end
  236.                     if upper(left(text.COMMENT.n, 3)) = 'CC:' | upper(left(text.COMMENT.n, 4)) = 'BCC:' | upper(left(text.COMMENT.n, 14)) = 'APPARENTLY-TO:' | upper(left(text.COMMENT.n, 10)) = 'RESENT-TO:' then do m = 1 to mlcount until msgfini = 1
  237.                         ccs = upper(compress(subword(text.COMMENT.n, 2), ',<>()'))
  238.                         do o = 1 to mlist.m.addrcount until msgfini = 1
  239.                             if index(ccs, upper(mlist.m.toaddr.o)) > 0 then do
  240.                                 call movemsg(msgs.curr, mlist.m.name, mlist.m.replyaddr)
  241.                                 mlfound = mlfound + 1
  242.                                 mlist.m.found = mlist.m.found + 1
  243.                                 msgfini = 1
  244.                                 end
  245.                             end
  246.                         end
  247.                     end
  248.                 end
  249.             end
  250.         end
  251.     end
  252.  
  253. cnt = 1
  254. if mlfound > 0 | dgparsed > 0 | rparsed > 0 then if stats = 1 then do
  255.     msgstem.TEXT.cnt = 'Sortmail processed 'msgs.count' message(s) and found:'; cnt = cnt + 1
  256.     msgstem.TEXT.cnt = ''; cnt = cnt + 1
  257.     if mlfound > 0 then do
  258.         msgstem.TEXT.cnt = mlfound' maillist message(s):'; cnt = cnt + 1
  259.         do n = 1 to mlcount
  260.             if mlist.n.found > 0 then do
  261.                 msgstem.TEXT.cnt = '  'mlist.n.found' message(s) from "'mlist.n.name'"'; cnt = cnt + 1
  262.                 end
  263.             end
  264.         end
  265.     if dgparsed > 0 then do
  266.         msgstem.TEXT.cnt = dgparsed' digest message(s) containing 'dgsubmsgs' sub-message(s):'; cnt = cnt + 1
  267.         do n = 1 to dgcount
  268.             if digest.n.found > 0 then do
  269.                 msgstem.TEXT.cnt = '  'digest.n.found' digest(s) from "'digest.n.name'"'; cnt = cnt + 1
  270.                 end
  271.             end
  272.         end
  273.     if rparsed > 0 then do; msgstem.TEXT.cnt = rparsed' AmiNet RECENT message(s) reporting 'rfiles' new files'; cnt = cnt + 1; end
  274.     end
  275. if amirep ~= '' then if aruu > 0 then do; msgstem.TEXT.cnt = 'AmigaReport uudecoded and put in your download directory'; cnt = cnt + 1; end
  276. if amilink ~= '' then if aluu > 0 then do; msgstem.TEXT.cnt = 'AmigaLink uudecoded and put in your download directory'; cnt = cnt + 1; end
  277.  
  278. msgstem.TEXT.COUNT = cnt - 1
  279. if msgstem.TEXT.COUNT > 0 then call writemsg
  280.  
  281. /* Update message list in Thor if the user is in the E-Mail conference */
  282.  
  283. address(thorport)
  284. CURRENTSYSTEM STEM bbs
  285. if bbs.CONFNAME = mailconf then SHOWCONFERENCE '"'mailconf'"'
  286. UPDATECONFWINDOW
  287.  
  288. signal cleanup
  289.  
  290. /* Some experimental error detection stuff */
  291.  
  292. error:
  293. syntax:
  294. if rc > 30 then say 'Error in line 'sigl': 'errortext(rc)
  295. else say 'Line 'sigl' returned 'rc
  296. say sourceline(sigl)
  297. if THOR.LASTERROR ~= 'THOR.LASTERROR' then say THOR.LASTERROR
  298. if BBSREAD.LASTERROR ~= 'BBSREAD.LASTERROR' then say BBSREAD.LASTERROR
  299.  
  300. /* Turn off copyback buffer */
  301.  
  302. break_c:
  303. halt:
  304. cleanup:
  305. address(bbsread)
  306. BUFMODE ENDCOPYBACK
  307.  
  308. /* Close progressbar if open */
  309.  
  310. if progwin ~= 0 then if progwin ~= 'PROGWIN' then do
  311.     address(thorport)
  312.     CLOSEPROGRESS REQ progwin
  313.     progwin = 0
  314.     end
  315.  
  316. /* Delete "Sortmail is running" file */
  317.  
  318. if exists("T:SortMail.tmp") then do
  319.     address(command)
  320.     "Delete T:SortMail.tmp QUIET"
  321.     end
  322.  
  323. exit(0)
  324.  
  325. /******************************************************************************
  326. ********************************** PROCEDURES *********************************
  327. ******************************************************************************/
  328.  
  329. /************************** Experimental writemsg() **************************/
  330.  
  331. writemsg: procedure expose thorport system mailconf msgstem. progwin
  332. address(bbsread)
  333. GETBBSDATA '"'system'"' bbsdata
  334. msgstem.FROMNAME = 'SortMail'
  335. msgstem.TONAME = bbsdata.USERNAME
  336. msgstem.SUBJECT = 'SortMail results'
  337. WRITEBRMESSAGE '"'system'"' '"'mailconf'"' STEM msgstem
  338. return
  339.  
  340.  
  341. /*************************** Parse digest messages ***************************/
  342.  
  343. parsedigest: procedure expose thorport system mailconf conflist. data. head. dgsubmsgs delusers progwin digest.
  344.              parse arg number, toconf, repaddr, endsubmsg, enddigest, deldigest, dgno
  345.  
  346. /* Read message text stem (head and data stem is already read) */
  347.  
  348. address(bbsread)
  349. READBRMESSAGE '"'system'"' '"'mailconf'"' number TEXTSTEM text
  350. if rc ~= 0 then do
  351.     address(thorport)
  352.     REQUESTNOTIFY '"Couldn''t read msg #'msgs.curr':\n'BBSREAD.LASTERROR'"' '"Ok"'
  353.     return
  354.     end
  355.  
  356. line = 1
  357.  
  358. do forever
  359.     drop newmsg.
  360.     newmsg.msgid = head.msgid
  361.     newmsg.replyconf = mailconf
  362.     newmsg.replyaddr = repaddr
  363.     newmsg.text.count = 0
  364.     fromline = 0; subjline = 0; dateline = 0
  365.     counted = 0; msgoffset = 0
  366.  
  367.     do until counted = 3
  368.         select
  369.             when upper(left(text.text.line, 5)) = "FROM:" then do
  370.                 counted = counted + 1 ; fromline = line ; end
  371.             when upper(left(text.text.line, 8)) = "SUBJECT:" then do
  372.                 counted = counted + 1 ; subjline = line ; end
  373.             when upper(left(text.text.line, 5)) = "DATE:" then do
  374.                 counted = counted + 1 ; dateline = line; end
  375.             when msgoffset > 100 then do
  376.                 address(thorport); REQUESTNOTIFY '"Failed to parse digest.\nOrgMsg: 'number'"' '"Ok"'; return; end
  377.  
  378.             when line > text.text.count then do
  379.                 drop data. head. text.
  380.                 if deldigest = 1 then do
  381.                     address(bbsread); UPDATEBRMESSAGE '"'system'"' '"'mailconf'"' number SETDELETED
  382.                     if rc ~= 0 then do
  383.                         address(thorport); REQUESTNOTIFY '"Couldn''t delete message #'number':\n'BBSREAD.LASTERROR'"' '"Ok"'; end
  384.                     end
  385.                 return
  386.                 end
  387.  
  388.             otherwise nop
  389.             end
  390.  
  391.         line = line + 1; msgoffset = msgoffset + 1
  392.     end
  393.  
  394.     newmsg.subject = "<no subject>"
  395.     newmsg.fromname = "Unknown"
  396.     newmsg.fromaddr = "<no address>"
  397.  
  398.     /* Some magic to find most name and address formats */
  399.  
  400.     from = strip(substr(text.text.fromline, 6))
  401.     from = translate(from, '<>', '()')
  402.     i = pos("<", from)
  403.     if i ~= 0 then do
  404.         checkaddr = strip(substr(from, i, pos('>', from) - i), B, ' <>"')
  405.         if pos("@", checkaddr) = 0 then do
  406.             newmsg.fromname = checkaddr
  407.             newmsg.fromaddr = strip(delstr(from, i, pos('>', from) - i), B, ' >')
  408.             end
  409.         else do
  410.             newmsg.fromaddr = checkaddr
  411.             newmsg.fromname = strip(delstr(from, i, pos('>', from) - i), B, ' ">')
  412.             end
  413.         end
  414.     else do
  415.         if pos("@", from) = 0 then do
  416.             newmsg.fromname = strip(from, B, ' "')
  417.             end
  418.         else do
  419.             newmsg.fromaddr = strip(from, B, ' "')
  420.             end
  421.         end
  422.  
  423.     newmsg.subject = strip(substr(text.text.subjline, 9))
  424.     newmsg.creationdatetxt = strip(substr(text.text.dateline, 6))
  425.  
  426.     do until text.text.line ~= ''
  427.         line = line + 1
  428.         end
  429.  
  430.     firstline = line
  431.     newmsg.text.count = 0
  432.     msgline = 0
  433.  
  434.     /* Search for 'End of message' line or the end of the digest */
  435.  
  436.     do until compare(upper(endsubmsg), upper(text.text.line)) = 0
  437.         if line = text.text.count then break
  438.         msgline = msgline + 1
  439.         newmsg.text.count = newmsg.text.count + 1
  440.         newmsg.text.msgline = text.text.line
  441.         line = line + 1
  442.         end
  443.  
  444.     address(bbsread)
  445.     WRITEBRMESSAGE '"'system'"' '"'toconf'"' STEM newmsg
  446.     if rc ~= 0 then do
  447.         address(thorport)
  448.         REQUESTNOTIFY '"WRITEBRMESSAGE:\n'BBSREAD.LASTERROR'"' '"Ok"'
  449.         end
  450.     else do
  451.         dgsubmsgs = dgsubmsgs + 1
  452.         digest.dgno.found = digest.dgno.found + 1
  453.         end
  454.     end
  455.  
  456.  
  457. /************************* Move mailing list mssages ************************/
  458.  
  459. movemsg: procedure expose thorport system mailconf conflist. data. head. text. textread delusers progwin
  460.          parse arg number, toconf, repaddr
  461.  
  462. CDF_NOT_ON_BBS          = '00008000'x  /* This conference is not on the bbs. */
  463.  
  464. priv = ""; urg = ""; imp = ""; kep = ""; repl = ""
  465.  
  466. /* Read text stem if it's not already read */
  467.  
  468. address(bbsread)
  469. if textread = 0 then do
  470.     READBRMESSAGE '"'system'"' '"'mailconf'"' number TEXTSTEM text
  471.     if rc ~= 0 then return
  472.     end
  473.  
  474. if (text.PART.COUNT = 0 | text.PART.COUNT = 'TEXT.PART.COUNT') & text.TEXT.COUNT = 0 then return
  475.  
  476. if head.fromname        ~= "HEAD.FROMNAME"        then text.fromname        = head.fromname
  477. if head.fromaddr        ~= "HEAD.FROMADDR"        then text.fromaddr        = head.fromaddr
  478. if head.toname          ~= "HEAD.TONAME"          then text.toname          = head.toname
  479. if head.toaddr          ~= "HEAD.TOADDR"          then text.toaddr          = head.toaddr
  480. if head.msgid           ~= "HEAD.MSGID"           then text.msgid           = head.msgid
  481. if head.refid           ~= "HEAD.REFID"           then text.refid           = head.refid
  482. if head.creationdate    ~= "HEAD.CREATIONDATE"    then text.creationdate    = head.creationdate
  483. if head.creationdatetxt ~= "HEAD.CREATIONDATETXT" then text.creationdatetxt = head.creationdatetxt
  484. if head.subject         ~= "HEAD.SUBJECT"         then text.subject         = head.subject
  485.  
  486. /* See if the conference the msg shall be written to exists */
  487.  
  488. do n = 1 to conflist.COUNT+1 while toconf ~= conflist.n
  489.     if n = conflist.COUNT+1 then do
  490.         /* Yikes! It doesn't exist! */
  491.         address(thorport)
  492.         REQUESTNOTIFY '"Non-existant conference: 'toconf'\nDo you want to create it?"' '"Yes|No"'
  493.         if result = 1 then do
  494.             /* Create the new conference */
  495.             address(bbsread)
  496.             CONFIGCONF '"'system'"' '"'toconf'"' SET c2x(CDF_NOT_ON_BBS)
  497.             /* Add the new conference to the conference list */
  498.             conflist.n = toconf
  499.             conflist.COUNT = conflist.COUNT + 1
  500.             end
  501.         else return
  502.         end
  503.     end
  504.  
  505. text.replyconf = mailconf
  506. if repaddr = '' | right(repaddr,7) = 'REPADDR' then text.replyaddr = head.replyaddr
  507.  
  508. if bittst(data.flags,2) then priv = "PRIVATE"
  509. if bittst(data.flags,11) then urg = "URGENT"
  510. if bittst(data.flags,12) then imp = "IMPORTANT"
  511.  
  512. /* Write the message to it's mailing list conference */
  513.  
  514. WRITEBRMESSAGE '"'system'"' '"'toconf'"' STEM text priv urg imp
  515. if rc ~= 0 then do 
  516.     address(thorport)
  517.     REQUESTNOTIFY '"WRITEBRMESSAGE:\n'BBSREAD.LASTERROR'"' '"Ok"'
  518.     return
  519.     end
  520. mnr = result
  521.  
  522. if delusers = 1 then do
  523.     /* Delete the new user added by ParseSOUP/UUCP */
  524.     SEARCHBRUSER BBSNAME '"'system'"' STEM suser SEARCH '"'text.fromaddr'"' ADDRESS
  525.     if result > 0 then do n = 1 to suser.COUNT
  526.         if suser.n.FOUNDINTAG = 1 then do
  527.             READBRUSER BBSNAME '"'system'"' USERNR suser.n.USERNR DATASTEM duser TAGSSTEM tuser
  528.             if rc ~= 0 then break
  529.             if value(data.msgdate) + 10 > duser.USERDATE then do
  530.                 if text.fromname = tuser.name then do
  531.                     WRITEBRUSER BBSNAME '"'system'"' UPDATEUSERNR suser.n.USERNR DELETEUSER
  532.                     end
  533.                 end
  534.             end
  535.         end
  536.     end
  537.  
  538. if bittst(data.flags, 7) then kep = "SETKEEP"
  539. if bittst(data.flags, 1) then repl = "SETREPLIED"
  540.  
  541. /* Give the new message it's flags */
  542.  
  543. UPDATEBRMESSAGE '"'system'"' '"'toconf'"' mnr kep repl HAZELEVEL data.HAZELEVEL
  544.  
  545. /* Delete the old message */
  546.  
  547. UPDATEBRMESSAGE '"'system'"' '"'mailconf'"' number SETDELETED
  548. if rc ~= 0 then do
  549.     address(thorport)
  550.     REQUESTNOTIFY '"Couldn''t delete message #'number':\n'BBSREAD.LASTERROR'"' '"Ok"'
  551.     address(bbsread)
  552.     end
  553.  
  554. drop data. head. text.
  555. return
  556.  
  557.  
  558. /*********************** Parse AmiNet RECENT messages ************************/
  559.  
  560. parseaminet: procedure expose thorport delnew system mailconf head. rparsed rfiles progwin delaminet bbsdata.
  561.              parse arg number
  562.  
  563. if right(bbsdata.BBSPATH, 1) ~= ':' | right(bbsdata.BBSPATH, 1) ~= '/' then bbsdata.BBSPATH = bbsdata.BBSPATH'/'
  564.  
  565. motd = 0
  566.  
  567. /* Save the message to a temporary file */
  568.  
  569. address(thorport)
  570. SAVEMESSAGE BBS '"'system'"' CONFNAME '"'mailconf'"' MSGNUMBER number FILENAME '"T:ParseAminet.tmp"' NOHEADER NOANSI
  571. if rc ~= 0 then return
  572.  
  573. call open(rf, "T:ParseAminet.tmp")
  574.  
  575. /* Delete the file and exit if it doesn't start with '|' (it's probably not a RECENT file) */
  576.  
  577. if left(readln(rf), 1) ~= '|' then do
  578.     address command
  579.     call close(rf)
  580.     'Delete T:ParseAminet.tmp QUIET'
  581.     return
  582.     end
  583.  
  584. rparsed = rparsed + 1
  585.  
  586. /* Update NewFiles.txt, delete it first if there's a old one there already */
  587.  
  588. if delnew = 0 then if exists(bbsdata.BBSPATH'Newfiles.txt') then do
  589.     address(command)
  590.     'Delete "'bbsdata.BBSPATH'Newfiles.txt" QUIET'
  591.     delnew = 1
  592.     end
  593.  
  594. if exists(bbsdata.BBSPATH'Newfiles.txt') then call open(ar, bbsdata.BBSPATH'Newfiles.txt', 'A')
  595. else call open(ar, bbsdata.BBSPATH'Newfiles.txt', 'W')
  596.  
  597. /* Process the RECENT message */
  598. address(bbsread)
  599.  
  600. do until eof(rf)
  601.     aline = readln(rf)
  602.     do while(left(aline, 1) = '|'); aline = readln(rf); end
  603.     if aline ~= "" then do
  604.         if aline = 'Message of the day:' then motd = 1
  605.         if motd = 1 then signal amifini
  606.         farea = word(aline, 2)
  607.         CONFIGFAREA '"'system'"' '"'farea'"'
  608.  
  609.         fname = word(aline, 1)
  610.         fdesc = right(aline, length(aline) - 35)
  611.         fsize = right(left(aline, 34), 5)
  612.         if(right(fsize, 1) = 'M') then mega = 1
  613.         else mega = 0
  614.  
  615.         fsize = compress(fsize, 'KM .')
  616.  
  617.         if(~datatype(fsize, 'W')) then fsize = 0
  618.         fsize = fsize * 1024
  619.         if(mega = 1) then fsize = trunc((fsize * 1024) / 10)
  620.  
  621.         if(fdesc ~= '') then do
  622.             drop brfile.
  623.             brfile.NAME = fname
  624.             brfile.SIZE = fsize
  625.             brfile.DATE = head.CREATIONDATE
  626.             brfile.DESCRIPTION.COUNT = 1
  627.             brfile.DESCRIPTION.1 = strip(fdesc)
  628.             WRITEBRFILE '"'system'"' '"'farea'"' STEM brfile
  629.             rfiles = rfiles + 1
  630.             call writeln(ar, aline)
  631.             end
  632.         end
  633.     end
  634.  
  635. amifini:
  636. call close(ar)
  637. call close(rf)
  638.  
  639. address(bbsread)
  640. GETBBSDATA '"'system'"' bbsdata
  641.  
  642. /* Delete the message and temporary file and return */
  643.  
  644. if delaminet = 1 & motd = 0 then do
  645.     address(bbsread)
  646.     UPDATEBRMESSAGE '"'system'"' '"'mailconf'"' number SETDELETED
  647.     if rc ~= 0 then do
  648.         address(thorport)
  649.         REQUESTNOTIFY '"Couldn''t delete message #'number':\n'BBSREAD.LASTERROR'"' '"Ok"'
  650.         address(bbsread)
  651.         end
  652.     end
  653.  
  654. address(command)
  655. 'Delete T:ParseAminet.tmp QUIET'
  656.  
  657. drop head. data. text.
  658.  
  659. return
  660.  
  661.  
  662. /********************** Open and read configuration file *********************/
  663.  
  664. readcfg: procedure expose cfgfile system mailconf aminet delaminet amirep amilink checkcc mlist. digest. mlcount dgcount stats delusers progwin msgs. bbs. thorport
  665.  
  666. call open(cf, cfgfile, 'R')
  667. do until eof(cf)
  668. subentry = ""
  669.     entry = readln(cf)
  670.     select
  671.         when upper(entry) = "SYSTEM" then do
  672.             do until upper(subentry) = "END"
  673.                 subentry = readln(cf)
  674.                 select
  675.                     when upper(subword(subentry, 1, 1)) = 'BBS:' then system = subword(subentry, 2)
  676.                     when upper(subword(subentry, 1, 1)) = 'CONF:' then mailconf = subword(subentry, 2)
  677.                     when upper(subword(subentry, 1, 1)) = 'AMINET:' then aminet = subword(subentry, 2)
  678.                     when upper(subword(subentry, 1, 1)) = 'DELAMINET:' then if upper(subword(subentry, 2, 1)) = 'YES' then delaminet = 1
  679.                     when upper(subword(subentry, 1, 1)) = 'AMIREP:' then amirep = subword(subentry, 2)
  680.                     when upper(subword(subentry, 1, 1)) = 'AMILINK:' then amilink = subword(subentry, 2)
  681.                     when upper(subword(subentry, 1, 1)) = 'CHECKCC:' then if upper(subword(subentry, 2, 1)) = 'YES' then checkcc = 1
  682.                     when upper(subword(subentry, 1, 1)) = 'STATISTICS:' then if upper(subword(subentry, 2, 1)) = 'YES' then stats = 1
  683.                     when upper(subword(subentry, 1, 1)) = 'DELUSERS:' then if upper(subword(subentry, 2, 1)) = 'YES' then delusers = 1
  684.                     otherwise nop
  685.                     end
  686.                 end
  687.  
  688.             /* Exit if we're on the wrong system */
  689.  
  690.             if system ~= bbs.BBSNAME then signal cleanup
  691.  
  692.             /* See if there's any messages to sort, exit if there isn't */
  693.  
  694.             address(thorport)
  695.             GETMESSAGEARRAY '"'mailconf'"' msgs LS
  696.             if rc = 5 then do
  697.                 signal cleanup
  698.                 end
  699.             else if rc ~= 0 then do
  700.                 REQUESTNOTIFY '"GETMESSAGEARRAY:\n'THOR.LASTERROR'"' '"Abort"'
  701.                 signal cleanup
  702.                 end
  703.             end
  704.  
  705.         when upper(entry) = "MAILLIST" then do
  706.             /* Read mailing list configuration */
  707.             mlcount = mlcount + 1
  708.             addrs = 0; names = 0
  709.             do until upper(subentry) = "END"
  710.                 subentry = readln(cf)
  711.                 select
  712.                     when upper(subword(subentry, 1, 1)) = 'LISTNAME:' then mlist.mlcount.name = subword(subentry, 2)
  713.                     when upper(subword(subentry, 1, 1)) = 'TOADDR:' then do
  714.                         addrs = addrs + 1
  715.                         mlist.mlcount.toaddr.addrs = subword(subentry, 2)
  716.                         end
  717.                     when upper(subword(subentry, 1, 1)) = 'TONAME:' then do
  718.                         names = names + 1
  719.                         mlist.mlcount.toname.names = subword(subentry, 2)
  720.                         end
  721.                     when upper(subword(subentry, 1, 1)) = 'FROMFIELD:' then mlist.mlcount.fromf = subword(subentry, 2)
  722.                     when upper(subword(subentry, 1, 1)) = 'REPLYADDR:' then mlist.mlcount.replyaddr = subword(subentry, 2)
  723.                     otherwise nop
  724.                     end
  725.                 mlist.mlcount.addrcount = addrs
  726.                 mlist.mlcount.namecount = names
  727.                 mlist.mlcount.found = 0
  728.                 end
  729.             end
  730.  
  731.         when upper(entry) = "DIGEST" then do
  732.             /* Read digest configuration */
  733.             dgcount = dgcount + 1
  734.             addrs = 0; names = 0
  735.             digest.dgcount.deldigest = 0
  736.             do until upper(subentry) = "END"
  737.                 subentry = readln(cf)
  738.                 select
  739.                     when upper(subword(subentry, 1, 1)) = 'DIGESTNAME:' then digest.dgcount.name = subword(subentry, 2)
  740.                     when upper(subword(subentry, 1, 1)) = 'TOADDR:' then do
  741.                         addrs = addrs + 1
  742.                         digest.dgcount.toaddr.addrs = subword(subentry, 2)
  743.                         end
  744.                     when upper(subword(subentry, 1, 1)) = 'TONAME:' then do
  745.                         names = names + 1
  746.                         digest.dgcount.toname.names = subword(subentry, 2)
  747.                         end
  748.                     when upper(subword(subentry, 1, 1)) = 'REPLYADDR:' then digest.dgcount.replyaddr = subword(subentry, 2)
  749.                     when upper(subword(subentry, 1, 1)) = 'ENDSUBMSG:' then digest.dgcount.endsubmsg = subword(subentry, 2)
  750.                     when upper(subword(subentry, 1, 1)) = 'ENDDIGEST:' then digest.dgcount.enddigest = subword(subentry, 2)
  751.                     when upper(subword(subentry, 1, 1)) = 'DELDIGEST:' then if upper(subword(subentry, 2, 1)) = 'YES' then digest.dgcount.deldigest = 1
  752.                     otherwise nop
  753.                     end
  754.                 digest.dgcount.addrcount = addrs
  755.                 digest.dgcount.namecount = names
  756.                 digest.dgcount.found = 0
  757.                 end
  758.             end
  759.         otherwise nop
  760.         end
  761.     end
  762. call close(cf)
  763. return
  764.